package com.controller;

import com.po.PermissionResourcePO;
import com.po.PermissionSysUserRolePO;
import com.po.SysUserRoleSaveBatchPO;
import com.result.Result;
import com.service.PermissionResourceService;
import com.service.PermissionSysUserRoleService;
import com.vo.PermissionResourceVO;
import com.vo.PermissionSysUserRoleVO;
import com.vo.SysUserRoleResourceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: chihaojie
 * @Date: 2019/5/29 16:34
 * @Version 1.0
 * @Note
 */

@Api(value = "sysUserRoleApi")
@CrossOrigin
@RestController
@RequestMapping("/sysUserRole")
public class PermissionSysUserRoleController {



    @Autowired
    private PermissionSysUserRoleService permissionSysUserRoleService;

    @ApiOperation(value = "保存", httpMethod = "POST", notes = "保存")
    @RequestMapping(value = "/save", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result<PermissionSysUserRoleVO> save(@RequestBody PermissionSysUserRolePO permissionResourcePO) {
        return new Result<PermissionSysUserRoleVO>().ok(permissionSysUserRoleService.save(permissionResourcePO));
    }


    /**
     * 批量保存账户角色关系
     * @author chihaojie
     * @param
     * @return
     */
    @ApiOperation(value = "批量保存账户角色关系", httpMethod = "POST", notes = "批量保存账户角色关系")
    @RequestMapping(value = "/saveBatch", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Result<Boolean> saveBatch(@RequestBody SysUserRoleSaveBatchPO sysUserRoleSaveBatchPO) {
        return new Result<Boolean>().ok(permissionSysUserRoleService.saveSysUserRoleBatch(sysUserRoleSaveBatchPO));
    }


    /**
     * 删除数据
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "remove账户角色关系", httpMethod = "GET", notes = "remove账户角色关系")
    @RequestMapping(value = "/remove/{id}")
    public Result<Boolean> remove(@PathVariable("id") Long id) {
        return new Result<Boolean>().ok(permissionSysUserRoleService.removeAccountRole(id));
    }

    /**
     * 根据账号id获取角色资源关系
     */
    @ApiOperation(value = "/getRoleResourceByAccountId", httpMethod = "GET", notes = "根据账号id获取角色资源关系")
    @RequestMapping(value = "/getRoleResourceByAccountId", method = RequestMethod.GET)
    public Result<SysUserRoleResourceVO> getRoleResourceByAccountId(@RequestParam("accountId") Long  accountId) {
        return new Result<SysUserRoleResourceVO>().ok(permissionSysUserRoleService.getRoleResourceByAccountId(accountId));
    }
}
